﻿using System.Linq.Expressions;

namespace AdminSystem.Repositories
{
    public interface IRepositories<TEntity> where TEntity : class
    {
        Task<int> Insert(TEntity entity);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> AddRange(IEnumerable<TEntity> entities);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<int> Delete(int id);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeleteRange(IEnumerable<int> ids);
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        Task<IList<TEntity>> GetAll();
        /// <summary>
        /// 根据条件查询多条
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> predicate);

        Task<List<TEntity>> GetAll<TKey>(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TKey>> orderby);

        Task<TEntity> GetById(int id);
        /// <summary>
        /// 根据条件查询是否存在
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> predicate);

        Task<int> Update(TEntity entity);
        Task<int> UpdateRange(IEnumerable<TEntity> entities);




    }
}
